/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs.persistencia;

import com.bs.util.TelaErro;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Bone
 */
public class Transaction implements EntityTransaction {

    org.hibernate.Transaction transaction;
    boolean rollbackOnly = true;

    public Transaction(org.hibernate.Transaction transaction) {
        this.transaction = transaction;
    }

    @Override
    public void begin() {
        try{
        transaction.begin();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
    }

    @Override
    public void commit() {
        try {
            transaction.commit();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
    }

    @Override
    public void rollback() {
        try{
        transaction.rollback();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
    }

    @Override
    public void setRollbackOnly() {
        rollbackOnly = true;
    }

    @Override
    public boolean getRollbackOnly() {
        return rollbackOnly;
    }

    @Override
    public boolean isActive() {
        return transaction.isActive();
    }
}
